package com.zzyl.nursing.controller.member;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.dto.FamilyMemberDto;
import com.zzyl.nursing.dto.QueryDeviceDataDto;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.vo.FamilyMemberVo;
import com.zzyl.nursing.vo.ListByPageVo;
import com.zzyl.nursing.vo.QueryDeviceDataVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户老人家属中间Controller
 *
 * @author ruoyi
 * @date 2025-01-10
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "客户老人家属中间的接口")
public class FamilyMemberElderController extends BaseController {
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    /**
     * 查询客户老人家属中间列表
     */
    @ApiOperation("查询客户老人家属中间列表")
    @PreAuthorize("@ss.hasPermi('nursing:familyMemberElder:list')")
    @GetMapping("/list")
    public TableDataInfo list(FamilyMemberElder familyMemberElder) {
        startPage();
        List<FamilyMemberElder> list = familyMemberElderService.selectFamilyMemberElderList(familyMemberElder);
        return getDataTable(list);
    }

    /**
     * 查询家人列表
     */
    @ApiOperation("查询家人列表")
    @GetMapping(value = "/my")
    public R<List<FamilyMemberVo>> getFamilyMemberElder() {
        List<FamilyMemberVo> list = familyMemberElderService.getFamilyMemberElder();
        return R.ok(list);
    }

    /**
     * 绑定家人
     */
    @ApiOperation("绑定家人")
    @PostMapping("/add")
    public AjaxResult add(@ApiParam(value = "绑定家人")
                          @RequestBody FamilyMemberDto familyMemberDto) {
        return toAjax(familyMemberElderService.insertFamilyMemberElder(familyMemberDto));
    }

    /**
     * 分页查询已绑定家人列表
     * @return 已绑定家人列表
     */
    @GetMapping("/list-by-page")
    @ApiOperation("分页查询已绑定家人列表")
    public R getByPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        List<ListByPageVo> list = familyMemberElderService.selectPage(pageNum,pageSize);
        return R.ok(list);
    }

    /**
     * 解绑家人
     */
    @ApiOperation("解绑家人")
    @DeleteMapping("/deleteById")
    public AjaxResult remove(@RequestParam("id") Long id) {
        return toAjax(familyMemberElderService.deleteFamilyMemberElderById(id));
    }

    /**
     * 根据 deviceName 和 productKey 查询设备数据
     */
    @ApiOperation("根据 deviceName 和 productKey 查询设备数据")
    @PostMapping("/QueryDevicePropertyStatus")
    public R getDeviceData(
            @ApiParam(value = "设备名称") @RequestBody QueryDevicePropertyStatusRequest request) {
        Object data = familyMemberElderService.getDeviceDataByDeviceNameAndProductKey(request);
        return R.ok(data);
    }

    /**
     * 按天统计查询指标数据
     * @return 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public R<List<QueryDeviceDataVo>> queryDeviceDataListByDay(QueryDeviceDataDto dto) {
        List<QueryDeviceDataVo> list = familyMemberElderService.queryDeviceDataListByDay(dto);
        return R.ok(list);
    }

    /**
     * 按周统计查询指标数据
     * @return 按周统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public R<List<QueryDeviceDataVo>> queryDeviceDataListByWeek(QueryDeviceDataDto dto) {
        List<QueryDeviceDataVo> list = familyMemberElderService.queryDeviceDataListByWeek(dto);
        return R.ok(list);
    }
}
